*********************************************************************************
/* Single-diff event study, by whether individual reports business income	*/
*********************************************************************************

* File paths
local datapath "${mvpf_audits}/data/cleaned" 
local datafolder "${mvpf_audits}/data/outside" 
local graphpath "${graphpath}" 

* Version of fig to produce 
global version  ${version} // paper or slides

* Other formatting
if "${version}" == "slides" {
	global title "title(" ", size(vhuge))"
	global img wmf
	graph set window fontface "Arial"
	global title "title(" ", size(vhuge))"
	global axis_size "" //xsize(6.5) ysize(4)" // makes figure wider
}

else if "${version}" == "paper" {
	global title "title("")"
	global img pdf
	graph set window fontface "LMRoman10-Regular"
	global title " "
	global axis_size " " // makes figure wider
}

/*------------------------------------------------------------------------------
Two year groupings
------------------------------------------------------------------------------*/
use "${mvpf_audits}/data/figures_rep/ap12.txt", clear

* keep coefficient of interest 
g row = _n
keep if inrange(row, 30, 57)
split v1, p(" # ") g(nrp)
carryforward nrp2, gen(nrp)
keep if nrp2 =="nrp=1"dg
drop nrp1 nrp2 row

split v1, p("=") g(a)
split a2, p(" # ") g(b)
destring b1, g(order)
drop a* b*
sort order 
drop v1

rename (totaltaxinclselfempminuseitcwins v4 ) (coeff_nonbus coeff_bus)
rename (v3 v5) (se_nonbus se_bus)

destring coeff* se*, replace
g row = _n
g event= row-14
g event2= row-14-0.3
*drop if missing(coeff)

* Generate standard errore and 95% CI
local specs "bus nonbus"
foreach spec of local specs{
	g coeff_`spec'_h = (coeff_`spec' + 1.96*se_`spec')
	g coeff_`spec'_l = (coeff_`spec' - 1.96*se_`spec')
}
*
keep coef* event*

/*------------------------------------------------------------------------------
Plot event studies by year
------------------------------------------------------------------------------*/
*
	
	twoway  (rspike coeff_nonbus_h coeff_nonbus_l event2, lc(gs9) lw(thin)) ///
			(scatter coeff_nonbus event2, mc(gs9) msize(small) ms(T)) ///
			(line coeff_nonbus event2, lc(gs9)) ///
			(rspike coeff_bus_h coeff_bus_l event, lc(gs4) lw(thin)) ///
			(scatter coeff_bus event, mc(gs4) msize(small) ms(O)) ///
			(line coeff_bus event, lc(gs4)) ///
			, ///
			xline(0.5, lw(vthin) lc(gs11)) ///
			yline(0, lw(vthin) lc(gs11)) ///
			xtitle("Year relative to tax year of audited return") ///
			ytitle("Taxes Paid") ///
			xlabel(-14(2)14 , nogrid)  ///
			ylab(, nogrid format(%5.0fc))  ///
			legend(ring(0) pos(11) row(2) symxsize(*0.3) order(5 2) ///
			lab(5 "Business income") lab(2 "No business income") ) ///
			${title} ${axis_size}	
graph export "`graphpath'/event_study_taxes_paid_bus_income.wmf", as(wmf) replace
